package com.gwclh.personnel.bean;

import com.gwclh.personnel.enums.ResultCode;
import lombok.Data;

@Data
//@AllArgsConstructor
//@NoArgsConstructor
public class ResultVo {
    Integer code;         //响应码
    private String msg;    //响应消息
    private Object data;       //具体前端数据

    //返回成功的消息,带数据
    public static ResultVo success(Object data) {
        return new ResultVo(ResultCode.SUCCESS, data);
    }
    // 返回成功的消息,不带数据
    public static ResultVo success() {
        return new ResultVo(ResultCode.SUCCESS, null);
    }

    //返回失败的消息,默认状态码400，没有提示信息
    public static ResultVo fail() {
        return new ResultVo(ResultCode.ERROR, null);
    }

    // 失败消息，默认状态码，可自定义提示消息
    public static ResultVo fail(String msg) {
        return new ResultVo(msg);
    }

    //  失败消息，自定义失败状态码与信息
    public static ResultVo fail(Integer code, String msg) {
        return new ResultVo(code, msg);
    }

    //返回失败的消息404
    public static ResultVo notFound() {
        return new ResultVo(ResultCode.NOT_FOUND, null);
    }

    //返回用户未认证
    public static ResultVo unauthorized() {
        return new ResultVo(ResultCode.UNAUTHORIZED, null);
    }

    //参数校验失败
    public static ResultVo validateFailed() {
        return new ResultVo(ResultCode.VALIDATE_FAILED, null);
    }

    // 返回内部错误
    public static ResultVo error(){
        return new ResultVo(ResultCode.ERROR,null);
    }


    //构造函数
    private ResultVo(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    private ResultVo(String msg) {
        this.code = 400;
        this.msg = msg;
        this.data = null;
    }

    private ResultVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }
}
